package com.ltsznh.android.bluecompass;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;

/**
 * Created by ltsznh on 13-12-11.
 */
public class CompassView extends SurfaceView implements Callback{

    public static CompassThread compassThread;//指南针线程

    public static Paint clearPaint = new Paint();
    private int cHeight;
    private int cWdith;

    public CompassView(Context context, AttributeSet attrs,int dd) {
        super(context, attrs, dd);
        init();
    }

    public CompassView(Context context, AttributeSet attrs) {
        super(context,attrs);
        init();
    }

    public CompassView(Context context) {
        super(context);
        init();
    }

    protected void init(){
        SurfaceHolder surfaceHolder = getHolder();
        surfaceHolder.addCallback(this);

        compassThread = new CompassThread(surfaceHolder);
        compassThread.start();



    }

    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        cWdith = getWidth();
        cHeight = getHeight();
        compassThread.setSize(cWdith,cHeight);

    }

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
        compassThread.run();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
    }


}
